package UPDchat;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class UdpReceiveDemo {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket(6666);
        while (true){
           //准备接收包裹
           byte[] bytes = new byte[1024];
           DatagramPacket packet = new DatagramPacket(bytes,0,bytes.length);
           socket.receive(packet);

            byte[] data = packet.getData();
            String receiveDate = new String(data, 0, data.length);
            System.out.println(receiveDate);
            if (data.equals("bye")){
                break;
            }
       }
       socket.close();
    }
}
